﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
var stationStore = new Ext.data.Store({
    proxy: new Ext.data.HttpProxy({
        url: '../Service/PatrolTaskViewService.aspx?Action=GetOrganization'
    }),
    reader: new Ext.data.JsonReader({
        root: 'topics',
        totalProperty: 'totalCount',
        id: 'Id',
        fields: ['Name', 'Id', 'Code']
    }),
    remoteStore: true

});
stationStore.load();
FantastPlatform.UI.OrgPatrolTaskGrid = function (config) {
    Ext.apply(this, config);

    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/PatrolTaskViewService.aspx?Action=LoadDetail'
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'ExecOrganization', 'BeginTime', 'EndTime','Points']
        }),
        remoteStore: true
    });
    /*
    var policeComboBox = new FantastPlatform.UI.AutoComplateComboBox({
    store: policeManStore,
    displayField: 'Name',
    valueField: 'Number',
    hiddenName: 'PoliceMan',
    typeAhead: true,
    mode: 'local',
    triggerAction: 'all',
    emptyText: '请选择警员...',
    selectOnFocus: true
    });
    */
    var squadronComboBox = new FantastPlatform.UI.AutoComplateComboBox({
        store: stationStore,
        displayField: 'Name',
        valueField: 'Id',
        hiddenName: 'PoliceSquadronCode',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText: '请选择执行单位...',
        selectOnFocus: true
    });

    //    squadronComboBox.on('select', function () {
    //        //alert(squadronComboBox.getValue());
    //        var id = GUID();
    //        detailWind = openWind("../PatrolTaskPointEditGrid.aspx?id="+0, id, '选择该班次的警员',700, 350, 'new_tab');
    //    });


    this.store = fileStore;
    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        defaultNum: 8
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();
    function icon(value, p, record) {
                if (record.data.Points == null){
                    record.data.Points = "[]";
                }
                return String.format(
               "&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"Images/preview.png\" qtip=\"添加点位\"></a>",
                                   record.id, record.data.Points);
      //  return "添加点位";
    }
    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    }, {
        header: '执行单位',
        dataIndex: 'ExecOrganization',
        width: 120,
        editor: new Ext.grid.GridEditor(squadronComboBox),
        sortable: true,
        renderer: function (value) {
            if (stationStore.getById(value) != null) {
                return stationStore.getById(value).json.Name
            }
            else {
                return ""
            }
        }
    }, {
        header: '开始时间',
        dataIndex: 'BeginTime',
        width: 120,
        editor: new Ext.grid.GridEditor(new Ext.form.TimeField({
            allowBlank: true,
            format: 'H:i'
        })),
        sortable: true
    }, {
        header: '结束时间',
        width: 120,
        dataIndex: 'EndTime',
        sortable: true,
        editor: new Ext.grid.GridEditor(new Ext.form.TimeField({
            format: 'H:i',
            allowBlank: true
        }))
    }, {
        header: '添加点位',
        width: 100,
        dataIndex: 'Url',
        renderer: icon
    }
    //    , {
    //        header: '执行单位人数',
    //        width: 80,
    //        dataIndex: 'SelfOrgPersonNum',
    //        sortable: true,
    //        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
    //            allowBlank: true
    //        }))
    //    }, {
    //        header: '执行单位车辆数',
    //        width: 80,
    //        dataIndex: 'SelfOrgCar',
    //        sortable: true,
    //        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
    //            allowBlank: true
    //        }))
    //    }, {
    //        header: '支援单位',
    //        width: 80,
    //        dataIndex: 'OtherOrgName',
    //        sortable: true,
    //        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
    //            allowBlank: true
    //        }))
    //    }, {
    //        header: '支援单位人数',
    //        width: 80,
    //        dataIndex: 'OtherOrgPersonNum',
    //        sortable: true,
    //        editor: new Ext.grid.GridEditor(new Ext.form.TextField({
    //            allowBlank: true
    //        }))
    //    }
    ];
    FantastPlatform.UI.OrgPatrolTaskGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
};
Ext.extend(FantastPlatform.UI.OrgPatrolTaskGrid, Ext.grid.EditorGridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.OrgPatrolTaskGrid.superclass.onRender.call(this, ct, position);
    },
    onViewDetailsClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行操作", "");
            } else {
                var fId = node[0].get('Id');
                if (fId != 0) {
                    var id = GUID();
                    detailWind = openWind('../PoliceManToScheduleGrid.aspx?id=' + fId, id, '查看该班次的警员或添加备注', 550, 350, 'edit');
                }
                else {
                    showErrorMessage("操作失败", "该记录还未保存", "");
                }
            }
        }
    }
});